home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 021-030 / amok24 / dme / src / source.zoo / filereq.c < prev    next >
C/C++ Source or Header  |  1989-07-03  |  5KB  |  197 lines

  1.  
  2. /*
  3.  *  ARP interface (ARPLOAD, ARPSAVE)
  4.  */
  5.  
  6. #include "defs.h"
  7.  
  8. extern PROC *proc;
  9.  
  10. void
  11. do_arpinsfile()
  12. {
  13.     char file[64];
  14.     char dir[64];
  15.     char path[128];
  16.     long oldlock = CurrentDir(Ep->dirlock);
  17.  
  18.     proc->pr_WindowPtr=(APTR)Ep->Win;
  19.     arp_pathname(Ep->dirlock,path,15);
  20.     file[0] = 0;
  21.     if (arpreq("INSERTFILE", file, path, Ep->Win)) {
  22.         CurrentDir(oldlock);
  23.         fixfile(file, path);
  24.         av[0] = (ubyte *)"i";
  25.         av[1] = (ubyte *)file;
  26.         do_edit();
  27.         return;
  28.     }
  29.     CurrentDir(oldlock);
  30. }
  31.  
  32. void
  33. do_arpload()
  34. {
  35.     char dir[64];
  36.     char file[64];
  37.     char path[128];
  38.     long oldlock = CurrentDir(Ep->dirlock);
  39.  
  40.     proc->pr_WindowPtr=(APTR)Ep->Win;
  41.     arp_pathname(Ep->dirlock,path,15);
  42.     file[0] = 0;
  43.     if (arpreq("NEWFILE", file, path, Ep->Win)) {
  44.         long newlock;
  45.         if (newlock = Lock(path, SHARED_LOCK)) {
  46.             UnLock(CurrentDir(oldlock));
  47.             Ep->dirlock = newlock;
  48.             av[0] = (ubyte *)"n";
  49.             av[1] = (ubyte *)file;
  50.             do_edit();
  51.             return;
  52.         }
  53.     }
  54.     CurrentDir(oldlock);
  55. }
  56.  
  57. void
  58. do_arpsave()
  59. {
  60.     char file[64];
  61.     char dir[64];
  62.     char path[128];
  63.     long oldlock = CurrentDir(Ep->dirlock);
  64.  
  65.     proc->pr_WindowPtr=(APTR)Ep->Win;
  66.     arp_pathname(Ep->dirlock,path,15);
  67.     splitpath(Ep->Name, file, dir);
  68.  
  69.     if (arpreq("SAVEAS", file, path, Ep->Win)) {
  70.         CurrentDir(oldlock);
  71.         fixfile(file,path);
  72.         av[1] = (ubyte *)file;
  73.         do_saveas();
  74.     } else {
  75.         CurrentDir(oldlock);
  76.     }
  77. }
  78.  
  79. fixfile(file,dir)
  80. register char *file,*dir;
  81. {
  82.     register char *ptr;
  83.     register short len = strlen(dir);
  84.     char hasdev = 0;
  85.  
  86.     /*
  87.      *  do we need to add a slash to the directory spec?
  88.      */
  89.  
  90.     if (len && dir[len-1] != '/' && dir[len-1] != ':') {
  91.         dir[len++] = '/';
  92.         dir[len] = 0;
  93.     }
  94.  
  95.     /*
  96.      *  Is file spec really a full path spec?
  97.      */
  98.  
  99.     for (ptr = file; *ptr; ++ptr) {
  100.         if (ptr[0] == ':')
  101.             hasdev = 1;
  102.     }
  103.     if (!hasdev) {
  104.         movmem(file,file+len,strlen(file)+1);
  105.         movmem(dir,file,len);
  106.     }
  107. }
  108.  
  109. /*
  110.  *  Search backwards for first ':' or '/' and split path there.
  111.  *  This subroutine may appear to be coded incorrectly to a novice
  112.  *  programmer.  It isn't [now].
  113.  */
  114.  
  115. splitpath(name, file, dir)
  116. register char *name;
  117. char *file, *dir;
  118. {
  119.     register short i;
  120.     for (i = strlen(name); i >= 0; --i) {       /* was (incorrectly) "i > 0" */
  121.         if (name[i] == ':' || name[i] == '/')
  122.             break;
  123.     }
  124.     ++i;
  125.     strcpy(file, name + i);
  126.     bmov(name, dir, i);
  127.     dir[i] = 0;
  128. }
  129.  
  130. #asm
  131.  
  132.                 ;   arpreq(hail,file,dir,window)
  133.  
  134.                 FAR DATA
  135.                 FAR CODE
  136.  
  137.                 public  _arpreq
  138.                 public  _LVOOldOpenLibrary
  139.                 public  _LVOCloseLibrary
  140.                 public  _SysBase
  141.  
  142. _LVOFileRequest equ     -294
  143.  
  144. arp_name_text   dc.b 'arp.library',0
  145.  
  146. fs              ds.l    1   ;hailing text
  147.                 ds.l    1   ;file name
  148.                 ds.l    1   ;directory
  149.                 ds.l    1   ;window requesting
  150.                 ds.w    1   ;LONG Align, idiots!  set to 0
  151.                 ds.l    1   ;func for wildcards
  152.                 ds.l    1   ;func to call w/intuimessages
  153.  
  154. _arpreq:
  155.                 lea.l   fs,A0
  156.                 movem.l 4(sp),D0-D3             ;setup fields
  157.                 movem.l D0-D3,(A0)
  158.                 clr.w   fs+16
  159.                 move.l  _SysBase,A6
  160.  
  161.                 lea.l   arp_name_text,a1        ;open library
  162.                 jsr     _LVOOldOpenLibrary(a6)
  163.                 tst.l   d0
  164.                 beq.s   done
  165.                 move.l  d0,a6
  166.                 lea.l   fs,a0
  167.                 jsr     _LVOFileRequest(A6)     ;call requestor
  168.                 move.l  D0,-(sp)                ;return value
  169.                 move.l  A6,A1                   ;CloseLibrary(arpbase)
  170.                 move.l  _SysBase,A6
  171.                 jsr     _LVOCloseLibrary(A6)
  172.                 move.l  (sp)+,D0                ;return value
  173. done            rts
  174.  
  175.                 XDEF    _arp_pathname
  176. _LVOPathName    EQU     -$14a
  177.  
  178. _arp_pathname:  move.l  _SysBase,A6
  179.  
  180.                 lea.l   arp_name_text,a1        ;open library
  181.                 jsr     _LVOOldOpenLibrary(a6)
  182.                 tst.l   d0
  183.                 beq.s   end
  184.                 move.l  d0,a6
  185.                 move.l  4(sp),d0
  186.                 move.l  8(sp),a0
  187.                 move.l  12(sp),d1
  188.                 jsr     _LVOPathName(a6)
  189.                 move.l  A6,A1                   ;CloseLibrary(arpbase)
  190.                 move.l  _SysBase,A6
  191.                 jsr     _LVOCloseLibrary(A6)
  192. end             rts
  193.  
  194. #endasm
  195.  
  196.  
  197.